<template>
    <el-form :model="peisong" label-position="right" label-width="auto">
        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="订单id:" prop="ddid">
                    <el-input v-model="peisong.ddid" placeholder="请输入订单id" clearable/>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="骑手id:" prop="qsid">
                    <el-input v-model="peisong.qsid" placeholder="请输入骑手id" clearable/>
                </el-form-item>
            </el-col>
        </el-row>

        <el-row :gutter="10">
            <el-col :span="12">
                <el-form-item label="配送开始时间" prop="psks">
                    <el-date-picker
                        v-model="peisong.psks"
                        type="datetime"
                    placeholder="请选择配送开始时间"
                    clearable
                    value-format="YYYY-MM-DD HH:mm:ss"
                    format="YYYY-MM-DD HH:mm:ss"
                    />
                </el-form-item>
                <el-form-item label="配送结束时间" prop="psjs">
                    <el-date-picker
                        v-model="peisong.psjs"
                        type="datetime"
                        placeholder="请选择配送结束时间"
                        clearable
                        value-format="YYYY-MM-DD HH:mm:ss"
                        format="YYYY-MM-DD HH:mm:ss"
                    />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="配送状态" prop="pszt">
                    <el-input v-model="peisong.pszt" placeholder="请输入配送状态" clearable/>
                </el-form-item>
            </el-col>
        </el-row>

    </el-form>

    <el-row>
        <el-col>
            <div style="text-align: center;">
                <el-button type="primary" @click="doSave">保存</el-button>
                <el-button @click="doCancel">取消</el-button>
            </div>
        </el-col>
    </el-row>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import {ElMessage} from "element-plus";
import axios from 'axios';

//---------------------------- 自定义组件事件 -----------------------------
const emits = defineEmits(["closeDialog", "flushPage"]);

const peisong = ref({
    psid: '',
    ddid: '',
    qsid: '',
    psks: '',
    psjs: '',
    pszt: 0
})

// 取消
const doCancel = () => {
    // 触发事件：关闭 dialog
    emits("closeDialog");
}

// 新增
const doSave = async () => {
    const {data} = await axios.post('/api/peisong', peisong.value);
    console.log(data);
    if (data.code === 200) {
        emits("flushPage");				// 触发事件： 刷新页面
        emits("closeDialog");			// 触发事件：关闭 dialog
        ElMessage.success("操作成功！");
    } else {
        ElMessage.error("操作失败！");
    }
}
</script>